var q6 = "#fUI/RunnerGame.img/RunnerGameUI/UI/Point/1#"
var tz12 = "#fEffect/CharacterEff/1112924/0/0#"; //黄星
var tz13 = "#fEffect/CharacterEff/1112925/0/0#"; //蓝星
var tz14 = "#fEffect/CharacterEff/1112926/0/0#"; //红星
var 黑水晶 = "#v4251402#";
var 五彩水晶 = "#v4251202#";
var ss1 = "#v4250802#";
var ss2 = "#v4251102#";
var ss3 = "#v4250902#";
var ss4 = "#v4251002#";
var 黄金 = "#v4011006#";
var 青铜 = "#v4011000#";
var 钢铁 = "#v4011001#";
var 祖母绿 = "#v4250002#";
var 祖母 = "#v4250702#";
var 海蓝 = "#v4250502#";
var 石榴 = "#v4250202#";
var 蛋白 = "#v4250302#";
var lengthsel;
var itemsel;
var currentItemQuantity;
var status=0;
var quantity1;
var quantity2;
var quantity3;
var quantity4;
var quantity5;
var itemarr = Array(
	Array(3, 4005004, 4251400, 4251401, 4251402), //黑暗水晶
	Array(3, 4251200, 4251201, 4251202), //五彩
	Array(3, 4005000, 4250800, 4250801, 4250802), //力量
	Array(3, 4005002, 4251100, 4251101, 4251102), //敏捷
	Array(3, 4005001, 4250900, 4250901, 4250902), //智慧
	Array(3, 4005003, 4251000, 4251001, 4251002), //幸运
	Array(3, 4021007, 4250000, 4250001, 4250002), //钻石
	Array(3, 4021003, 4250700, 4250701, 4250702), //祖母绿
	Array(3, 4021002, 4250500, 4250501, 4250502), //海蓝
	Array(3, 4021000, 4250200, 4250201, 4250202), //石榴
	Array(3, 4021004, 4250300, 4250301, 4250302), //蛋白
	Array(10, 4010006, 4011006), //金块
	Array(10, 4010000, 4011000), //青铜
	Array(10, 4010001, 4011001) //青铜

);

function start() {
	status = -1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (mode == 0 && status == 0) {
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			var text = "#e#r " + q6 + "只要您辛勤劳动就可获得制作装备的材料哦" + q6 + "#n\r\n";
			text += "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "#k#k";
			text += "#r      - <尊敬的玩家我能帮你你制作合成各宝石.矿物.水晶材料> -  #n\r\n";
			text += "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "" + tz13 + "" + tz14 + "" + tz12 + "#k#k";	
			for (var i = 0; i < itemarr.length; i++) {
				if (itemarr[i][0] == 3) {
					text += "#b#L" + i + "##v" + itemarr[i][1] + "##z" + itemarr[i][1] + "#-制作 #k<下等-中等-高等>#l\r\n";
				} else {
					text += "#b#L" + i + "##v" + itemarr[i][2] + "##z" + itemarr[i][2] + "#-制作 #d<矿母合成>#l\r\n";
				}
			}
			cm.sendSimple(text);
		} else if (status == 1) {
			lengthsel = selection;
			var text= "#e#r " + q6 + "请选择要制造的材料品质" + q6 + "#n\r\n";
			if(itemarr[lengthsel][1]==4251200){//下等五彩
				for (var i = 1; i < itemarr[lengthsel].length; i++) {
					text += "#b#L" + i + "##v" + itemarr[lengthsel][i] + "##z" + itemarr[lengthsel][i] + "#-制作 #k#l\r\n";
				}
			}else{
				for (var i = 2; i < itemarr[lengthsel].length; i++) {
					if (itemarr[lengthsel][0] == 3&&itemarr[lengthsel][i-1]!=4251200) {
						text += "#b#L" + i + "##v" + itemarr[lengthsel][i] + "##z" + itemarr[lengthsel][i] + "#-制作 #k#l\r\n";
					}else{
						text += "#b#L" + i + "##v" + itemarr[lengthsel][i] + "##z" + itemarr[lengthsel][i] + "#-制作 #d<矿母合成>#l\r\n";
					}
				}
			}
			
			cm.sendSimple(text);

		} else if (status == 2) {
			itemsel = selection;
			currentItemQuantity = cm.getItemQuantity(itemarr[lengthsel][itemsel - 1]);
			var color = "#g";
			if (currentItemQuantity < itemarr[lengthsel][0]){
				color = "#r";
			}
			var txt = "制作#e#d#v" + itemarr[lengthsel][itemsel] + "#你所需要筹备的材料：#n#k\r\n\r\n#b";
			if(itemarr[lengthsel][itemsel]==4251200){//下等五彩
				
				 quantity1 = cm.getItemQuantity(4005000);
				 quantity2 = cm.getItemQuantity(4005001);
				 quantity3 = cm.getItemQuantity(4005002);
				 quantity4 = cm.getItemQuantity(4005003);
				 quantity5 = cm.getItemQuantity(4005004);
				
				txt += "当前已有："+color+quantity1+"/#v4005000# X 1 \r\n";
				txt += "当前已有："+color+quantity2+"/#v4005001# X 1 \r\n";
				txt += "当前已有："+color+quantity3+"/#v4005002# X 1 \r\n";
				txt += "当前已有："+color+quantity4+"/#v4005003# X 1 \r\n";
				txt += "当前已有："+color+quantity5+"/#v4005004# X 1 \r\n";
				if(quantity1>0&&quantity2>0&&quantity3>0&&quantity4>0&&quantity5>0){
					currentItemQuantity=5;
				}
			}else{
				txt += "当前已有："+color+currentItemQuantity+"/#v"+itemarr[lengthsel][itemsel - 1]+"# X "+itemarr[lengthsel][0];
				
			}
			txt+="#k\r\n\r\n- #e#d管理提示：#n#b输入要制作的数量：#k";
			cm.sendGetText(txt);
		} else if (status == 3) {
			if((/(^[1-9]\d*$)/).test(cm.getText())&&itemarr[lengthsel][itemsel]==4251200&&cm.getText()<=quantity1&&cm.getText()<=quantity2&&cm.getText()<=quantity3&&cm.getText()<=quantity4&&cm.getText()<=quantity5){//下等五彩
				cm.gainItem(4005000,-cm.getText());
				cm.gainItem(4005001,-cm.getText());
				cm.gainItem(4005002,-cm.getText());
				cm.gainItem(4005003,-cm.getText());
				cm.gainItem(4005004,-cm.getText());
				cm.gainItem(itemarr[lengthsel][itemsel], cm.getText());
				cm.sendSimple("制作成功！！！");
				cm.dispose();
				return ;
			}
			if ((/(^[1-9]\d*$)/).test(cm.getText())&&currentItemQuantity>=(cm.getText()*itemarr[lengthsel][0])) {
					cm.gainItem(itemarr[lengthsel][itemsel-1], -(cm.getText()*itemarr[lengthsel][0]));
					cm.gainItem(itemarr[lengthsel][itemsel], cm.getText());
					cm.sendSimple("制作成功！！！");
			}else{
				cm.sendSimple("你材料不够啊小老弟，乖乖输入正确数量！");
				cm.dispose();
				return ;
			}
			cm.dispose();
		}
	}
}